//
//  ViewController.m
//  betta
//
//  Created by betta on 5/15/15.
//  Copyright (c) 2015 Zhao Jing. All rights reserved.
//

#import "ViewController.h"
#import "GopayMobilePay.h"
#import "XMLDictionary.h"
#import "MD5GenerateParse.h"

@interface ViewController ()<GopayMobilePayDelegate>
@property (strong, nonatomic)GopayMobilePay* mobilePlay;
@property (strong, nonatomic)NSDictionary *dic;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.mobilePlay  = [[GopayMobilePay alloc]init];
    self.mobilePlay.delegate = self;
    
//    NSDictionary *dic = @{@"version":@"3.0",
//                          @"language":@"1",
//                          @"signType":@"",
//                          @"tranCode":@"8888",
//                          @"merId":@"0000003152",
//                          @"merOrderNum":@"2011092200001",
//                          @"tranAmt":@"10.00",
//                          @"feeAmt":@"1.00",
//                          @"currencyType":@"156",
//                          @"merNotifyUrl":@"http://www.xxx.com/response.do",
//                          @"tranDateTime":@"20081107094626",
//                          @"tranIp":@"127.0.0.1",
//                          @"deviceModel":@"HTC One",
//                          @"receiveAccount":@"000000001000000584",
//                          @"imeiCode":@"358848048725980",
//                          @"phoneNumber":@"18777776666",
//                          @"clientPosition":@"39.324234,116.34324",
//                          @"isRepeatSubmi":@"1",
//                          @"goodsName":@"全聚德烤鸭",
//                          @"goodsDetail":@"好吃不贵",
//                           @"buyerName":@"张三",
//                           @"buyerContact":@"010-88888888",
//                           @"note1":@"",
//                           @"note2":@"",
//                           @"remark":@"",
//                           @"signValue":@"049dbb2ab29a13facb9f868ff87f61f3"
//                          };

//    self.dic = @{@"paymentInfo":dic};
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)buttonTap:(id)sender {
    
    //xml
   NSString *strInputTemp= [self.dic  XMLString];
    NSString *strInput = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>%@",strInputTemp ];
   //加密数据“mer_id&receiver_account&notify_url&mer_order_id&mer_datetime&amount&fee_amt&currency_type&verify_code”
    NSString *str = @"utf8&3.0&128&c&14&13&13&1&2";
    NSString *strMd5 =[[[MD5GenerateParse alloc]init]generateMd5WithString:str];
    UIViewController *view = [self.mobilePlay BeginGopayMobilePay:strMd5];
    
    [self presentViewController:view animated:YES completion:^{
        
    }];
}


#pragma mark GopayMobilePayDelegate
-(void)CloseMobilePay:(id)sender
{
    if(sender)
    {
        NSDictionary *dic = [NSDictionary dictionaryWithXMLString:sender];
    }
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"dismiss view");
    }];
}

@end
